// 题意：网格图求一个左上到右下的最小割。老题了。
//
// 题解：平面图对偶图求最短路。外面无穷平面再划分成两个平面。
//
// run: time $exec < input
#include <iostream>
#include <vector>

template <class T>
struct shortest_path_faster_algorithm
{
	typedef T value_type;
	typedef int size_type;

	struct edge {
		edge(size_type from, size_type to, value_type cost) : from(from), to(to), cost(cost) {}
		size_type from, to;
		value_type cost;
	};

	typedef std::vector<edge> adj_edge;
	typedef typename adj_edge::iterator edge_iter;
	typedef std::vector<adj_edge> graph_type;
//	enum { inf = 1 << 28 };
	value_type static const inf = 1 << 28;

	shortest_path_faster_algorithm(size_type n) : n(n)
	{
		graph.resize(n);
		dist.resize(n);
		in_queue.resize(n);
		count_into_que.resize(n);
		dq_size = 2 * n;
		dq.resize(dq_size);
	}

	void add_edge(size_type from, size_type to, value_type cost)
	{
		graph[from].push_back(edge(from, to, cost));
		graph[to].push_back(edge(to, from, cost));
	}

	value_type spfa(size_type source, size_type target)
	{
		std::fill(dist.begin(), dist.end(), +inf);
		std::fill(in_queue.begin(), in_queue.end(), false);
		std::fill(count_into_que.begin(), count_into_que.end(), 0);
		clear();
		push_back(source);
		dist[source] = 0;
		in_queue[source] = true;
		count_into_que[source]++;
		while (!empty()) {
			size_type now = front();
			in_queue[now] = false;
			pop_front();

			for (edge_iter it = graph[now].begin(); it != graph[now].end(); ++it) {
				size_type v = it->to;
				value_type c = it->cost;
				if (dist[v] > dist[now] + c) {
					dist[v] = dist[now] + c;
					if (!in_queue[v]) {
						if (count_into_que[v] >= n) return -inf;
						if (!empty() && dist[v] < dist[front()])
							push_front(v);
						else
							push_back(v);
						in_queue[v] = true;
						count_into_que[v]++;
					}
				}
			}
		}
		return dist[target];
	}

private:
	size_type next(int x) { return (x + 1) % dq_size; }
	size_type prev(int x) { return (x + dq_size - 1) % dq_size; }
	void clear() { head = tail = 0; }
	bool empty() { return head == tail; }
	size_type front() { return dq[head]; }
	void push_back(size_type x) { dq[tail] = x; tail = next(tail); }
	void push_front(size_type x) { dq[head = prev(head)] = x; }
	void pop_front() { head = next(head); }

	graph_type graph;
	size_type n;
	size_type dq_size;
	size_type head, tail;
	std::vector<size_type> dq;
	std::vector<size_type> count_into_que;
	std::vector<value_type> dist;
	std::vector<char> in_queue; // FIXME std::vector<bool>;
};

int n, m, s, t;

int squre_index(int x, int y, int opt)
{
	if (x < 1 || y > m) return s;
	if (y < 1 || x > n) return t;
	int tmp = (x - 1) * m + y;
	return 2 * tmp + opt;
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n >> m;
	n--; m--;
	s = 0; t = n * m * 2 + 1;

	shortest_path_faster_algorithm<int> sp(n * m * 2 + 4);
	for (int i = 1; i <= n + 1; i++)
		for (int j = 1, x, y, c; j <= m; j++) {
			std::cin >> c;
			x = squre_index(i-1, j, 0);
			y = squre_index(i, j, -1);
			sp.add_edge(x, y, c);
		}

	for (int i = 1; i <= n; i++)
		for (int j = 1, x, y, c; j <= m + 1; j++) {
			std::cin >> c;
			x = squre_index(i, j - 1, -1);
			y = squre_index(i, j, 0);
			sp.add_edge(x, y, c);
		}

	for (int i = 1; i <= n; i++)
		for (int j = 1, x, y, c; j <= m; j++) {
			std::cin >> c;
			x = squre_index(i, j, -1);
			y = squre_index(i, j, 0);
			sp.add_edge(x, y, c);
		}

	std::cout << sp.spfa(s, t) << '\n';
}

